(function(vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addProductSeckillInfo: {
                categoryId: '',
                productId: '',
                valueId: '',
                killId: '',
                prodName: '',
                prodDesc: '',
                killHours: '',
                continueHours: '',
                totalCount: '',
                oneCount: '',
                killPrice: '',
                killStock: '',
                state: '',
                startTime: '',
                endTime: '',
                productCategorys: [],
                products: [],
                values: [],
                selectsHours:[
                    8,10,12,14,15,16,20,22
                ]
            }
        },
        _initMethod: function() {
            $that._listAddProductCategorys();
            vc.initDate('addProductSeckillStartTime', function(_time) {
                $that.addProductSeckillInfo.startTime = _time;
            });
            vc.initDate('addProductSeckillEndTime', function(_time) {
                $that.addProductSeckillInfo.endTime = _time;
            })
        },
        _initEvent: function() {
            vc.on('addProductSeckill', 'openAddProductSeckillModal', function() {
                $('#addProductSeckillModel').modal('show');
            });
        },
        methods: {
            addProductSeckillValidate() {
                return vc.validate.validate({
                    addProductSeckillInfo: $that.addProductSeckillInfo
                }, {

                    'addProductSeckillInfo.prodDesc': [{
                            limit: "required",
                            param: "",
                            errInfo: "秒杀产品简介不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "256",
                            errInfo: "秒杀产品简介不能超过256"
                        },
                    ],
                    'addProductSeckillInfo.killHours': [{
                            limit: "required",
                            param: "",
                            errInfo: "秒杀小时不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "秒杀小时不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.continueHours': [{
                            limit: "required",
                            param: "",
                            errInfo: "持续小时不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "持续小时不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.totalCount': [{
                            limit: "required",
                            param: "",
                            errInfo: "有效期内购买次数不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "有效期内购买次数不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.oneCount': [{
                            limit: "required",
                            param: "",
                            errInfo: "一次购买数量不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "一次购买数量不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.killPrice': [{
                            limit: "required",
                            param: "",
                            errInfo: "秒杀金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "秒杀金额不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.killStock': [{
                            limit: "required",
                            param: "",
                            errInfo: "限量不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "限量不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.state': [{
                            limit: "required",
                            param: "",
                            errInfo: "状态不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "状态不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.startTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "开始时间不能超过12"
                        },
                    ],
                    'addProductSeckillInfo.endTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "结束时间'不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "结束时间'不能超过12"
                        },
                    ],
                });
            },
            saveProductSeckillInfo: function() {
                if (!$that.addProductSeckillValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addProductSeckillInfo.shopId = vc.getCurrentCommunity().shopId;

                vc.http.apiPost(
                    '/productSeckill.saveProductSeckill',
                    JSON.stringify($that.addProductSeckillInfo), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addProductSeckillModel').modal('hide');
                            $that.clearAddProductSeckillInfo();
                            vc.emit('productSeckillManage', 'listProductSeckill', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddProductSeckillInfo: function() {
                let _productCategorys = $that.addProductSeckillInfo.productCategorys;
                let _products = $that.addProductSeckillInfo.products;
                $that.addProductSeckillInfo = {
                    categoryId: '',
                    productId: '',
                    valueId: '',
                    killId: '',
                    prodName: '',
                    prodDesc: '',
                    killHours: '',
                    continueHours: '',
                    totalCount: '',
                    oneCount: '',
                    killPrice: '',
                    killStock: '',
                    state: '',
                    startTime: '',
                    endTime: '',
                    productCategorys: _productCategorys,
                    products: _products,
                    values: [],
                    selectsHours:[
                        8,10,12,14,15,16,20,22
                    ]
                };
            },
            _listAddProductCategorys: function() {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/productCategory.queryProductCategory',
                    param,
                    function(json, res) {
                        let _productCategoryManageInfo = JSON.parse(json);
                        $that.addProductSeckillInfo.productCategorys = _productCategoryManageInfo.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _changeAddProductCatalorys: function(_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        shopId: vc.getCurrentCommunity().shopId,
                        cataloryId: $that.addProductSeckillInfo.cataloryId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/product.queryProduct',
                    param,
                    function(json, res) {
                        let _productManageInfo = JSON.parse(json);
                        $that.addProductSeckillInfo.products = _productManageInfo.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _changeAddProduct: function() {

                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        shopId: vc.getCurrentCommunity().shopId,
                        productId: $that.addProductSeckillInfo.productId
                    }
                };
                //发送get请求
                vc.http.apiGet('/product.queryProduct',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.addProductSeckillInfo.values = _json.data[0].productSpecValues;
                        $that.addProductSeckillInfo.prodDesc = _json.data[0].prodDesc;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _getValueSpecName: function(_value) {
                let _specName = "";
                _value.productSpecDetails.forEach(item => {
                    _specName += (item.detailValue + ";");
                })
                return _specName;
            }
        }
    });

})(window.vc);